﻿<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <!--_meta 作为公共模版分离出去-->
    <% layout("/common/_meta.html",{title:"修改商品"}){} %>
    <!--_meta 作为公共模版分离出去-->
</head>
<body style="background-color:#fff">
<div class="wap-container">
    <div class="panel">
        <div class="panel-body">
            <form action="${ctxPath}/item/update" method="post" class="form form-horizontal" id="form-item-update" enctype="multipart/form-data">
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>商品名称：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <input type="hidden" value="${item.id}" name="id" id="id">
                        <input type="text" class="input-text" value="${item.title!}" placeholder="商品名称" id="title" name="title">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3">简介：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <textarea id="introduction" name="introduction" cols="" rows="" class="textarea"  placeholder="商品简介">${item.introduction!}</textarea>
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3">图片：</label>
                    <div class="form-controls col-xs-8 col-sm-9">
                        <span class="btn-upload">
                            <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                            <input type="file" multiple name="img" id="btn-upload-file-thumb" class="input-file" onchange="previewFile()" accept="image/jpeg,image/png,image/gif,image/bmp">
                        </span>
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3">预览：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <img src="${item.mainImg1Url}" height="100%" width="100%" class="thumbnail">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>类型：</label>
                    <div class="form-controls col-xs-8 col-sm-8">
                        <span class="select-box">
                            <select class="select" name="categoryId" size="1">
                                <%for(certType in types){%>
                                    <option value="${certType.id}">${certType.name}</option>
                                <option value="${certType.id}"
                                    <%if(certType.id == item.categoryId){%>
                                    selected
                                    <%}%>
                                    >${certType.name}</option>
                                <%}%>
                            </select>
                        </span>
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>价格：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <input type="number" class="input-text" value="${item.price!}" placeholder="价格" id="price" name="price">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>总数量：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <input type="number" class="input-text" value="${item.totalCount!}" placeholder="总数量" id="totalCount" name="totalCount">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>库存：</label>
                    <div class="formControls col-xs-8 col-sm-8">
                        <input type="number" class="input-text" value="${item.leftCount!}" placeholder="库存" id="leftCount" name="leftCount">
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-xs-8 col-sm-8 col-xs-offset-3 col-sm-offset-3">
                        <button type="submit" class="btn btn-success btn-block radius">修改商品</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<% layout("/common/_footer.html"){} %>
<% layout("/common/_validate.html"){} %>
<!--/_footer 作为公共模版分离出去-->
<script type="text/javascript">
    $(function(){

        $("#form-department-add").validate({
            rules:{
                title:{
                    required:true,
                    maxlength:50
                },
                introduction:{
                    maxlength:255
                },
                totalCount:{
                    required:true
                },
                leftCount:{
                    required:true
                },
                price:{
                    required:true
                }
            },
            submitHandler:function(form){
                loading();
                form.submit();
            }
        });
    });

    function previewFile() {
        var preview = document.querySelector('img');
        var file    = document.querySelector('input[type=file]').files[0];
        var reader  = new FileReader();

        reader.onloadend = function () {
            preview.src = reader.result;
        }

        if (file) {
            reader.readAsDataURL(file);
        } else {
            preview.src = "";
        }
    }
</script>
</body>
</html>
